home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_100 / 173_01 / ctoc.lxi < prev    next >
Text File  |  1980-01-01  |  2KB  |  73 lines

  1.  
  2. /*
  3.  * ctoc.lxi  --  Convert old C operators to new C form
  4.  *
  5.  * Adapted from example in C. Forsythe's LEX manual.
  6.  *
  7.  * NOTE:
  8.  *      Forsythe's program put an entire comment into the token
  9.  *      buffer. Either define a huge token buffer for my typical
  10.  *      monster comments, or filter text within comments as if
  11.  *      it were real C code. This is what I did. So =+ inside
  12.  *      a comment will get changed to +=, etc.  Note tnat you
  13.  *      may use the commen() function in LEXLIB if you want the
  14.  *      comments eaten. I wanted 'em in the output.
  15.  * by
  16.  *      Bob Denny
  17.  *      28-Feb-81
  18.  */
  19.  
  20. %{
  21.  
  22. char tbuf[80];          /* Token buffer */
  23.  
  24. main()
  25.   {
  26.   while (yylex())
  27.     ;
  28.   }
  29.  
  30. %}
  31.  
  32. any             = [\0-\177];
  33. nesc            = [^\\];
  34. nescquote       = [^\\"];
  35. nescapost       = [^\\'];
  36. schar           = "\\" any | nescquote;
  37. cchar           = "\\" any | nescapost;
  38. string          = '"' schar* '"';
  39. charcon         = "'" cchar* "'";
  40. %%
  41.  
  42. "=" ( << | >> | "*" | + | - | "/" | "%" | "&" | "|" | "^" )
  43.                 {
  44.                 gettoken(tbuf, sizeof tbuf);
  45.                 printf("%s=",tbuf+1);
  46.                 }
  47.  
  48. [<=>!]"=" | "="[<>]
  49.                 {
  50.                 lexecho(stdout);
  51.                 }
  52.  
  53. "=" / ( ++ | -- )
  54.                 {
  55.                 lexecho(stdout);
  56.                 }
  57.  
  58. charcon
  59.                 {
  60.                 lexecho(stdout);
  61.                 }
  62.  
  63. string
  64.  
  65.                 {
  66.                 lexecho(stdout);
  67.                 }
  68.  
  69. [\0-\377]
  70.                 {
  71.                 lexecho(stdout);
  72.                 }
  73.  O oGÇIá ╧MαO≡ Q S@U`